<?php
define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined


session_name('cuatrovientos');
// Starting the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks
session_start();

if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
{
	// If you are logged in, but you don't have the tzRemember cookie (browser restart)
	// and you have not checked the rememberMe checkbox:

	$_SESSION = array();
	session_destroy();
	
	// Destroy the session
}

 if($_GET["l"] == 1) 
			{
			$_SESSION = array();			
			session_destroy();
			header("Location: index.php");
			exit;
			} 
			

/*if(isset($_GET['logoff']))
{
	$_SESSION = array();
	session_destroy();
	
	header("Location: demo.php");
	exit;
}*/

if($_POST['submit']=='Login')
{
	// Checking whether the Login form has been submitted
	
	$err = array();
	// Will hold our errors
	
	
	if(!$_POST['log'] || !$_POST['pwd'])
		$err[] = 'All the fields must be filled in!';
	
	if(!count($err))
	{
		$_POST['log'] = mysql_real_escape_string($_POST['log']);
		$_POST['pwd'] = mysql_real_escape_string($_POST['pwd']);
		$_POST['rememberMe'] = (int)$_POST['rememberMe'];
		
		// Escaping all input data
								//incluir cifrado
		$row = mysql_fetch_assoc(mysql_query("SELECT * FROM profesores WHERE login='".$_POST['log']."' AND pass='".$_POST['pwd']."'"));

		if($row['login'])
			{
				// If everything is OK login
				$_SESSION['usr']=$row['login'];
				$_SESSION['id'] = $row['cod'];
				//$_SESSION['rememberMe'] = $_POST['rememberMe'];
				
				
				// Store some data in the session
				
				setcookie('tzRemember',$_POST['rememberMe']);
			}
		else $err[]='Wrong username and/or password!';
	}
	else
	{
	echo $err;
	}
	/*if($err)
	$_SESSION['msg']['login-err'] = implode('<br />',$err);
	// Save the error messages in the session

	header("Location: demo.php");
	exit;*/

}

$script = '';

if($_SESSION['msg'])
{
	// The script below shows the sliding panel on page load
	
	$script = '
	<script type="text/javascript">
	
		$(function(){
		
			$("div#panel").show();
			$("#toggle a").toggle();
		});
	
	</script>';
	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	
  	<title>El Justiciero - Cuatrovientos</title>
  	<meta name="description" content="Pagina de ajusticiamiento para profesor@s de cuatrovientos" />
  	<meta name="keywords" content="cuatrovientos, puntuaciones, alumnos" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />	
	
	<!-- stylesheets -->
  	<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
  	<link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" />
	
    <!-- jQuery - the core -->
	<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
	<!-- Sliding effect -->
	<script src="js/slide.js" type="text/javascript"></script>

</head>

<body>
<?php
if(!$_SESSION['id']):
// If you are not logged in
include_once "nologgeado.php";
?>

<?php
else:
	
// If you are logged in

include_once "loggeado.php";
?>


<?php
endif;
// Closing the IF-ELSE construct
?>


</body>
</html>
